<?php 
/**
 * @version        $Id$
 * @author         master@xuewl.com
 * @copyright      Copyright (c) 2007 - 2014, Chongqing xuewl Information Technology Co., Ltd.
 * @link           http://www.xuewl.com
**/
namespace Member\Controller;
use \Admin\Controller\InitController;
/**
 * 后台会员模型管理
 */
class RewardController extends InitController {
	public function _initialize() {
		parent::_initialize();
		$this->db = D('Score');
		$this->user_db=D('Member');
		$this->pagecurr = max(1, I('page', 0, 'intval'));
		$this->pagesize =10;
	
	}

	/**
	 * 奖励查询管理
	 * @author xuewl <master@xuewl.com>
	 */
	public function manage() {
	    $sqlMap=array();
	    $sqlMap['u_type']= array('NEQ','u_bean') ;
	    $sqlMap['c_type']=array('EQ',1);
	    if (submitcheck('search')) {
	    	$info=I('param.');
	        $start = (!empty($info['start_time'])) ? strtotime($info['start_time']) : 0;
			$end = (!empty($info['end_time'])) ? strtotime($info['end_time']) : 0;
		    if ($start&&$end){
				$end += 86400;
			$sqlMap['posttime']=array(array('EGT',$start),array('lt',$end),'and');
			}elseif($start>0){
			$sqlMap['posttime']=array(array('EGT',$start));
			}elseif ($end>0){
				$end += 86400;
			$sqlMap['posttime']=array(array('lt',$end));
				
			}
			
			if ($info['uid']>0){
			  $sqlMap['userid']=array(array('EQ',$info['uid']));
			}
	    }
	 	$rewardcount = $this->db->where($sqlMap)->count();
		$rewardlist = $this->db->where($sqlMap)->page($this->pagecurr, $this->pagesize)->select();
		$userid = array();
		foreach ($rewardlist as $v){
			$userid[]=$v['userid'];
		}
       $ids = array_unique($userid);
       $sqlmap=array();
       $sqlmap['userid']=array('IN',$ids);
       $user=$this->user_db->where($sqlmap)->select();
	   $pages = page($rewardcount, $this->pagesize);
		/* 附加菜单 */
	   $form =  new \Common\Library\form();
	   include $this->admin_tpl('reward_list');
		
	}


//删除操作
    public function delete(){
      if(!empty($_GET['id'])){
            $id = $_GET['id'];
            $result = $this->db->delete_content($id);
            if($result){
               $this->success('操作成功', 'javascript:close_dialog();', 2);
            }else{
            	  $this->error('操作失败！');
            }
        }
        if(!empty($_POST['ids'])) {
            $result = $this->db->delete_content($_POST['ids']);
            if($result)
            {
               $this->success('操作成功', 'javascript:close_dialog();', 2);
            }else{
            	  $this->error('操作失败！');
            }
        }   
    }

}